using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ByHand.Model;
using ByHand.Data;
using ByHand.Services.Interfaces;
using ByHand.Data.Interfaces;
using ByHand.Services.Code;

namespace ByHand.Services.Implements
{
    public class OrderLogService : RepositoryBase<OrderLog>, IOrderLogService
    {
        public OrderLogService(IDatabaseFactory DbFactory) : base(DbFactory) { }



        public List<OrderLog> GetByPage(int page, int pagesize, out int total)
        {
            var lst = from o in ByHandDB.OrderLogs
                      orderby o.DateTime descending
                      select o;
            total = lst.Count();
            return lst.Skip((page - 1) * pagesize).Take(pagesize).ToList();
        }

        public List<OrderLog> GetByPageFilter(int page, int pagesize, out int total, string filter)
        {
            var intfilter = -1;
            if (!Int32.TryParse(filter, out intfilter))
            {
                //can not parse will set intfilter=0
                intfilter = -1;
            }
            var lst = from o in ByHandDB.OrderLogs
                      where o.OrderID.Equals(intfilter)
                      || o.UserName.Contains(filter)
                      || o.UserType.Contains(filter)
                      || o.ActionType.Contains(filter)
                      || o.ByHandName.Contains(filter)
                      orderby o.DateTime descending
                      select o;
            total = lst.Count();
            return lst.Skip((page - 1) * pagesize).Take(pagesize).ToList();
        }
    }
}
